import com.kyub.buganville.Role
import com.kyub.buganville.User
import com.kyub.buganville.UserRole
import com.kyub.buganville.Artifact

class BootStrap {

   def springSecurityService

   def init = { servletContext ->

      def adminRole = new Role(authority: 'ROLE_ADMIN').save(flush: true)
      def userRole = new Role(authority: 'ROLE_USER').save(flush: true)

      String password = springSecurityService.encodePassword('password')
      def testUser = new User(username: 'me', enabled: true, password: password)
      testUser.save(flush: true)

      UserRole.create testUser, adminRole, true

      assert User.count() == 1
      assert Role.count() == 2
      assert UserRole.count() == 1

      def artifact = new Artifact(name:"demo artifact" , description:"Demo demo demo")
      artifact.save(flush: true)
   }
}